package com.tepth.busfix.main.repair;

import com.tepth.busfix.bean.reponse.Process;
import com.tepth.busfix.bean.reponse.Repair;
import com.tepth.busfix.network.ApiModel;
import com.tepth.busfix.network.observer.SimpleDisposableObserver;

import java.util.List;

/**
 * Created by TMVPHelper on 2017/03/15
 */
public class RepairPresenter extends RepairContract.Presenter {

    @Override
    public void getRepair() {
        mRxManager.add(mModel.getRepair(mView.getAuthKey(), mView.getBusId())
                .subscribeWith(new SimpleDisposableObserver<ApiModel<Repair>>(mView) {
                    @Override
                    public void onSucceed(Object o) {
                        Repair repair = (Repair) o;
                        mView.showRepair(repair);
                    }
                }));
    }

    @Override
    public void postRepair() {
        mRxManager.add(mModel.postRepair(mView.getAuthKey(), mView.getRepairInfo())
                .subscribeWith(new SimpleDisposableObserver<ApiModel<String>>(mView) {
                    @Override
                    public void onSucceed(Object o) {
                        mView.postRepairInfoSucceed();
                    }
                }));
    }

    @Override
    public void getProcess() {
        mRxManager.add(mModel.getProcess(mView.getAuthKey(), mView.getTroubleTypeId()
                ,mView.getTroubleName())
                .subscribeWith(new SimpleDisposableObserver<ApiModel<List<Process>>>(mView) {
                    @Override
                    public void onSucceed(Object o) {
                        List<Process> list = (List<Process>) o;
                        mView.showProcess(list);
                    }
                }));
    }

    @Override
    public void cancelPunchCard() {
        mRxManager.add(mModel.cancelPunchCard(mView.getAuthKey(), mView.getCancelPunchJson())
                .subscribeWith(new SimpleDisposableObserver<ApiModel<String>>(mView) {
                    @Override
                    public void onSucceed(Object o) {
                        mView.showCancelPunchSucceed();
                    }
                }));
    }
}